package com.eqdd.yiqidian.ui.tongxunlu;

import android.content.DialogInterface;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.TeamManageActivityCustom;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.MainActivity;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

public class TeamManageActivity extends BaseActivity {
    private TeamManageActivityCustom dataBinding;
    private String groupid;
    private String groupname;
    private AlertDialog alertDialog;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_team_manage);
        initTopTitleBar(View.VISIBLE, "管理群");
    }

    @Override
    public void initData() {
        groupid = getIntent().getStringExtra("groupid");
        groupname = getIntent().getStringExtra("groupname");
    }

    @Override
    public void setView() {


    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.oiv_remove:
                Bundle bundle = new Bundle();
                bundle.putString("groupid", groupid);
                bundle.putString("groupname", groupname);
                startActivity(TeamRemoveActivity.class, bundle);
                break;
            case R.id.oiv_dismiss:
                if (alertDialog == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setMessage("确认解散群吗?");
                    builder.setTitle("提示");
                    builder.setPositiveButton("确认", (dialog, which) -> {
                        dialog.dismiss();
                        OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.DISMISS_GROUP)
                                .params("userGuid", user.getGuid())
                                .params("Groupid", groupid)
                                .execute(new DialogCallBack<HttpResult>(this) {
                                    @Override
                                    public void onSuccess(Response<HttpResult> response) {
                                        HttpResult httpResult = response.body();
                                        ToastUtil.showShort(httpResult.getMsg());
                                        if (httpResult.getStatus() == 200) {
                                            startActivity(MainActivity.class);
                                        }
                                    }
                                });

                    });
                    builder.setNegativeButton("取消", (DialogInterface dialog, int which) -> {
                                dialog.dismiss();
                            }
                    );
                    alertDialog = builder.create();
                }
                alertDialog.show();
                break;
        }
    }
}
